define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wuliu/wlshouru/index' + location.search,
                    add_url: 'wuliu/wlshouru/add',
                    edit_url: 'wuliu/wlshouru/edit',
                    del_url: 'wuliu/wlshouru/del',
                    multi_url: 'wuliu/wlshouru/multi',
                    import_url: 'wuliu/wlshouru/import',
                    table: 'wlshouru',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        //
                        {field: 'id', title: __('Id'),visible: true },
                        //付款单位
                        {field: 'danwei', title: __('Danwei'), operate:'like' ,visible: true },
                        //车号
                        {field: 'chehao', title: __('Chehao'), operate:'like' ,visible: true },
                        //缴费人员
                        {field: 'driver', title: __('Driver'), operate:'like' ,visible: true },
                        //项目
                        {field: 'leixing', title: __('Leixing'), operate:'like' ,visible: true },
                        //收款方式
                        {field: 'sktype', title: __('Sktype'), operate:'like' ,visible: true },
                        //收入(人民币)
                        {field: 'shouru', title: __('Shouru'), operate:'BETWEEN',visible: true },
                        //支出
                        {field: 'zhichu', title: __('Zhichu'), operate:'BETWEEN',visible: true },
                        //结余
                        {field: 'jieyu', title: __('Jieyu'), operate:'BETWEEN',visible: true },
                        //收款时间
                        {field: 'sktime', title: __('Sktime'), operate:'RANGE', addclass:'datetimerange', datetimeFormat:'YYYY/MM/DD' , formatter: Table.api.formatter.datetime},
                        //备注
                        {field: 'beizhu', title: __('Beizhu'), operate:'like' ,visible: true },
                        //收费人
                        {field: 'shoufeiyuan', title: __('Shoufeiyuan'), operate:'like' ,visible: true },
                        //
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', datetimeFormat:'YYYY/MM/DD' , formatter: Table.api.formatter.datetime},
                        //
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', datetimeFormat:'YYYY/MM/DD' , formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'wuliu/wlshouru/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'wuliu/wlshouru/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'wuliu/wlshouru/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
